﻿Imports System.Threading.Tasks

Public Class Nebenleistung
    Private loader As FuncClasses.IDatabase
    Private _main As Window1
    Public Sub New(window As Window1)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()
        loader = window.Database
        _main = window
        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        Dim showit As Boolean
        Try
            showit = CBool(loader.GetSettingByKey("shownldiscount"))
        Catch ex As Exception
            showit = True
        End Try
        If showit Then
            window.AddNewWelcomeInfo(Me)
        End If
    End Sub

    Private Sub CheckBox1_Checked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CheckBox1.Checked
        loader.SetSettingByKey("shownldiscount", "False")
    End Sub

    Private Sub CheckBox1_Unchecked(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles CheckBox1.Unchecked
        loader.SetSettingByKey("shownldiscount", "True")
    End Sub

    Private Sub TextBlock1_MouseUp(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) Handles TextBlock1.MouseUp
        ProgressBar.Visibility = Windows.Visibility.Visible
        Task.Factory.StartNew(Sub()
                                  'Parallel.ForEach(_main.OrderViewModel.AllOrders, Sub(o As FuncClasses.Order)
                                  '                                                     If o.Rebate > 0 Then
                                  '                                                         For Each a In o.OrderedArticles
                                  '                                                             If a.ArticleCategory.Contains("Nebenleistung") Then
                                  '                                                                 Dim rabatt As Double = a.OrderRebate / 100
                                  '                                                                 rabatt = (1 - o.Rebate) * (1 - rabatt)
                                  '                                                                 a.OrderRebate = (1 - rabatt) * 100
                                  '                                                             End If
                                  '                                                         Next
                                  '                                                         'ToDo: Speichern
                                  '                                                     End If
                                  '                                                 End Sub)

                                  _main.OrderViewModel.Refresh()
                                  loader.SetSettingByKey("shownldiscount", "False")
                                  _main.Dispatcher.BeginInvoke(Sub()
                                                                   ProgressBar.Visibility = Windows.Visibility.Hidden
                                                                   BlockFinished.Visibility = Windows.Visibility.Visible
                                                               End Sub)
                              End Sub)
    End Sub
End Class
